package com.zk;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;

import java.util.Arrays;

/**
 * 绑定主机
 */
public class ZK0015 {
    public static void main(String[] args) {
        String key="dcdz7XRvlnygvzz5PX0H";
        String icode="0015";
        String data = "{\n"
                + "  \"licensePlate\": \"苏AN0163\",\n"
                + "  \"address\": \"上海市青浦区人民政府(公园路北),上海市青浦区公园路86弄28号\",\n"
                + "  \"latitude\": 31.14979,\n"
                + "  \"longitude\": 121.12426,\n"
                + "  \"contactName\": \"黄超凡\",\n"
                + "  \"contactNumber\": \"15139738476\",\n"
                + "  \"driverName\": \"黄超凡\",\n"
                + "  \"driverNumber\": \"17839999394\",\n"
                + "  \"reportCity\": \"上报城市-杭州\",\n"
                + "  \"truckRouteName\": \"车辆线路-深圳-杭州\",\n"
                + "  \"serviceTimeType\": \"场站服务\",\n"
                + "  \"departureTime\": \"2024-05-20 15:14:00\",\n"
                + "  \"serviceRescueOptionName\": \"轮胎故障\",\n"
                + "  \"serviceRescueOptionDescription\": \"\",\n"
                + "  \"commonAttachmentList\": []\n"
                + "}";
        String secret="1f7NGmxOVTjREKjNRWNNabGbM21UgDaZ";
        String nonce =  "11231231";
        JSONObject dataBody = new JSONObject();
        dataBody.put("key", key);
        dataBody.put("secret", secret);
        String timeStamp = String.valueOf(System.currentTimeMillis());
        dataBody.put("ts", timeStamp);
        dataBody.put("icode", icode);
        dataBody.put("dataBody", data);
        dataBody.put("nonce", nonce);
        String[] validateArray = new String[] { key, timeStamp, data, nonce};
        Arrays.sort(validateArray);
        String digestHex = SecureUtil.hmacSha1(secret).digestHex(ArrayUtil.join(validateArray, ""));
        dataBody.put("sig", digestHex);
        System.out.println(dataBody);
//        String response = HttpUtil.post("https://sh.sy.tehst.56luntai.com:18886/dache-wmms-admin/api/common/if", dataBody.toString(), 5 * 1000);
        String response = HttpUtil.post("127.0.0.1:8080/dache-wmms-admin/api/common/if?icode=0015", dataBody.toString(), 5 * 1000);
//        String response = HttpUtil.post("http://www.56dache.com/dache-wmms-admin/api/common/if", dataBody.toString(), 5 * 1000);
        System.out.println(response);
    }



    public void test() {
        String key = "dcdz7XRvlnygvzz5PX0H";
        String icode = "0015";
        String data = "{\n"
                + "  \"licensePlate\": \"苏AN0163\",\n"
                + "  \"address\": \"上海市青浦区人民政府(公园路北),上海市青浦区公园路86弄28号\",\n"
                + "  \"latitude\": 31.14979,\n"
                + "  \"longitude\": 121.12426,\n"
                + "  \"contactName\": \"韩浩浩\",\n"
                + "  \"contactNumber\": \"15139738476\",\n"
                + "  \"driverName\": \"杨福霞\",\n"
                + "  \"driverNumber\": \"17839999394\",\n"
                + "  \"reportCity\": \"上报城市-杭州\",\n"
                + "  \"truckRouteName\": \"车辆线路-深圳-杭州\",\n"
                + "  \"serviceTimeType\": \"场站服务\",\n"
                + "  \"departureTime\": \"2024-05-20 15:14:00\",\n"
                + "  \"serviceRescueOptionName\": \"轮胎故障\",\n"
                + "  \"serviceRescueOptionDescription\": \"\",\n"
                + "  \"commonAttachmentList\": []\n"
                + "}";
        String secret = "1f7NGmxOVTjREKjNRWNNabGbM21UgDaZ";
        String nonce = "11231231";
        JSONObject dataBody = new JSONObject();
        dataBody.put("key", key);
        dataBody.put("secret", secret);
        String timeStamp = String.valueOf(System.currentTimeMillis());
        dataBody.put("ts", timeStamp);
        dataBody.put("icode", icode);
        dataBody.put("dataBody", data);
        dataBody.put("nonce", nonce);
        String[] validateArray = new String[] { key, timeStamp, data, nonce };
        Arrays.sort(validateArray);
        String digestHex = SecureUtil.hmacSha1(secret).digestHex(ArrayUtil.join(validateArray, ""));
        dataBody.put("sig", digestHex);
        System.out.println(dataBody);
    }


}
